package com.neu.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.neu.entity.Disecategory;
import com.neu.mapper.DiseCategoryMapper;
import com.neu.service.DiseaseService;
import com.neu.service.DisecategoryService;



@Service
public class DisecategoryServiceImpl implements DisecategoryService{
	@Autowired
	private DiseCategoryMapper diseCategoryMapper;
	@Autowired
	private DiseaseService diseaseService;
	@Override
	public List<Disecategory> getAllDiseCategory(String dicaName,int dicaType) {
		// TODO Auto-generated method stub
		return diseCategoryMapper.getAllDiseCategory(dicaName,dicaType);
	}
	@Override
	public boolean addDiseCategory(Disecategory disecategory) {
		// TODO Auto-generated method stub
		int save = diseCategoryMapper.addDiseCategory(disecategory);
		boolean flag = false;
		if(save>0) {
			flag = true;
		}
		return flag;
	}
	@Override
	public boolean updateDiseCategory(Disecategory disecategory) {
		// TODO Auto-generated method stub
		int upd = diseCategoryMapper.updateDiseCategory(disecategory);
		boolean flag = false;
		if(upd>0) {
			flag = true;
		}
		return flag;
	}
	@Override
	public List<Disecategory> pageDiseCategoryQuery(int page, int limit, String dicaName, int dicaType) {
		// TODO Auto-generated method stub
		return diseCategoryMapper.pageDiseCategoryQuery(page, limit, dicaName, dicaType);
	}
	@Override
	public int pageDiseCategoryTotal(String dicaName, int dicaType) {
		// TODO Auto-generated method stub
		return diseCategoryMapper.pageDiseCategoryTotal(dicaName, dicaType);
	}
	@Override
	public boolean delereDiseCategoryQuery(int id) {
		// TODO Auto-generated method stub
		int diseCategoryID = id;
//		先删除疾病基本信息
		Integer[] ids =  diseaseService.getDiseaseIds(diseCategoryID);
		boolean flag = diseaseService.delDiseaseByIds(ids);
		if(flag) {
			int del =  diseCategoryMapper.delereDiseCategoryQuery(id);
			if(del>0) {
				return true;
			}else {
				return false;
			}
		}
		return flag;
		
	}
	
}
